import { createHelia } from 'helia'
import { json } from '@helia/json'
import {CID} from "multiformats";

// 创建Helia实例
const helia = await createHelia()

// 创建JSON传输实例
const heliaJson = json(helia)

// 添加一个JSON对象
const cid1 = await heliaJson.add({ hello: 'world' })
console.log("CID =", cid1.toString())

// 根据CID获取JSON内容
const cid2 = CID.parse('bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
const jsonObj = await heliaJson.get(cid2)
console.log("根据CID获取JSON:", jsonObj)